/*********************************************************
 *
 *  Ports all the way down - patwd
 *  ------------------------------
 *
 *  debug.h
 *
 *  Copyright (C) 2012 by Sebastian Roschke (bykhee@gmail.com)
 *
 *  Logging and debug function definitions.
 *
 *  Distributed under the terms and conditions of GNU LGPL.
 *
 *********************************************************/

#include <string.h>
#include <stdio.h>

#include "debug.h"

int log_level;

void log_debug(u8* msg) {
  if (log_level) {
    printf("[D] %s\n", (char*)msg);
  }
}

void log_error(u8* msg) {
  fprintf(stderr, "\e[0;31m[ERROR]\e[m %s\n", (char*)msg);
}

void logg(u8* msg) {
  printf("[+] %s\n", (char*)msg);
}

void print_dump(void* data, int size) {

  if (!log_level) return;

  int i = 0;

  printf("------------------DUMP------------------------\n");
  while (i < size) {
    printf("%02x ", ((unsigned char*)data)[i++]);
    if (i % 20 == 0 || i == size)
      printf("\n");
  }
  printf("------------------END-------------------------\n");

}

